package com.ruoyi.carShop.controller;

import com.ruoyi.carShop.domain.RepairReservation;
import com.ruoyi.carShop.service.RepairReservationService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author:严瑞
 * @Date ：2024/9/13 17:19
 */
@RestController
@RequestMapping("/repair")
public class RepairReservationController extends BaseController {

    @Autowired
    private RepairReservationService repairReservationService;

    /*查询维修任务列表*/
    @PostMapping("list")
    public AjaxResult list(@RequestBody(required = false) RepairReservation repairReservation){
        List<RepairReservation> list = repairReservationService.selectRepairReservationList(repairReservation);
        return AjaxResult.success(list);
    }

    /*查询维修任务列表*/
    /*@GetMapping("list")
    public AjaxResult list(RepairReservation repairReservation){
        List<RepairReservation> list = repairReservationService.selectRepairReservationList(repairReservation);
        return AjaxResult.success(list);
    }*/

    /*查看维修任务详情*/
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long repairReservationId){
        return AjaxResult.success("成功获取维修任务详情", repairReservationService.selectRepairReservationById(repairReservationId));
    }


    /*核销维修任务（确认到场-更新到场时间，维修状态，删除状态）*/
    @PutMapping("/update/{id}")
    public AjaxResult update(@PathVariable("id") Long id) {
        RepairReservation repairReservation = new RepairReservation();
        repairReservation.setRepairReservationId(id);
        Integer i = repairReservationService.updateRepairReservation(repairReservation);
        if (i != 0){
            return AjaxResult.success(repairReservationService.selectRepairReservationById(id)) ;
        } else {
            return AjaxResult.error();
        }
    }
}
